<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css" />
	</head>
	<style type="text/css">
		.mui-table-view-cell {
			padding: 5px 10px;
			position: relative;
		}
		
		.list_detail .mui-media-body p {
			margin-top: 15px;
		}
		
		.list_detail .mui-media-body span {
			position: absolute;
			right: 30px;
			margin-top: -30px;
		}
		
		.print {
			margin-top: 10px;
			color: #000;
		}
		
		.amount {
			text-align: center;
			font-size: 16px;
			padding: 15px 0;
			border-bottom: 1px solid #999;
			overflow: hidden;
		}
		
		.list_d img {
			padding: 10px;
		}
		
		.amount div {
			width: 50%;
			float: left;
			height: 100%;
		}
		
		.amount .left {
			border-right: 1px solid #C9C9C9;
		}
		
		.amount div span {
			font-size: 24px;
			color: deepskyblue;
		}
		
		.mui-input-group .mui-checkbox{
			width: 45%;
			display: inline-block;
		}
		.mui-input-group{
			background-color: initial;
			margin-top: 15px;
		}
		.mui-input-group:before, .mui-input-group:after, .mui-input-group .mui-checkbox:after{
			height: 0;
		}
	</style>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">支付账单明细</h1>
			<a class="mui-pull-right print">打印</a>
		</header>
		<!--下拉刷新容器-->
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<!--数据列表-->
				
				<ul class="mui-table-view mui-table-view-chevron listResult">
					<div class="amount">
						<div class="left">
							<span id="price">0.00</span>元
							<h5>累计金额</h5>
						</div>
						<div class="right">
							<span id="bishu">0</span>笔
							<h5>成交笔数</h5>
						</div>
					</div>
				</ul>
			</div>
		</div>
		
			
		<script type="text/javascript" src="../js/jquery-2.1.0.js"></script>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/config.js"></script>
		<script type="text/javascript" src="../js/mobile-detect.min.js" ></script>
		<script type="text/javascript" src="../js/common.js"></script>
		<script>
			mui.plusReady(function() {
				//页面初始化
				var self = plus.webview.currentWebview();
				var searchTime = self.searchTime;
				var dataTime = self.timess;
				var time1 = self.start_time;
				var time2 = self.end_time;
				var countA = 1;
				var statusSign = false;
				var pageNum = 10;
				mui.init({
					pullRefresh: {
						container: '#pullrefresh',
						auto: false,
						up: {
							contentrefresh: '正在加载...',
							callback: pullupRefresh
						}
					}
				});

				/**
				 * 下拉刷新具体业务实现
				 */
				function pullupRefresh() {
					setTimeout(function() {
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(statusSign); //参数为true代表没有更多数据了。
						refresh();
					}, 1500);
				}

				function refresh() {
					ajaxRequest();
				}
				switch(dataTime) {
					case "1":
						today();
						break;
					case "2":
						yesterday();
						break;
					case "3":
						lastweek();
						break;
					case "4":
						thisMonth();
						break;
					case "5":
						lastMouth();
						break;
					case "0":
						zidingyi();
					default:
						break;
				}

				function ajaxRequest(number) {
					require(weburl + model1, "json", "post", {
						token: localStorage.getItem("token"),
						time_type: dataTime ? dataTime : "",
						time_start: time1,
						time_end: time2,
						page: countA,
						number: pageNum
					}, function(data) {
						dataX(data);
					}, function() {
						$(".noData").css("display", "block");
					})
				}

				function amount(number) {
					require(weburl + model1, "json", "post", {
						token: localStorage.getItem("token"),
						time_type: number ? number : "",
						time_start: time1,
						time_end: time2
					}, function(response) {
						$('#price').html(response.count.amount);
						$("#bishu").html(response.count.bisu);
					}, function() {
						mui.toast('网络错误', {  
							duration: 'long',
							type: 'div'
						})
					})

				}

				//今天的数据
				function today() {
					var time = new Date();
					time1 = time.getFullYear() + "-" + (time.getMonth() < 9 ? "0" + (time.getMonth() + 1) : (time.getMonth() + 1)) + "-" + (time.getDate() < 10 ? "0" + time.getDate() : time.getDate() + " " + "00:00:00");
					time2 = time.getFullYear() + "-" + (time.getMonth() < 9 ? "0" + (time.getMonth() + 1) : (time.getMonth() + 1)) + "-" + (time.getDate() < 10 ? "0" + time.getDate() : time.getDate() + " " + "23:59:59");
					amount(dataTime);
					ajaxRequest(dataTime);
				}

				//昨天的数据
				function yesterday(response) {
					//					var time = new Date((new Date()) - 86400000);
					//昨天的时间
					time1 = getYesterday() + " " + "00:00:00";
					time2 = getYesterday() + " " + "23:59:59";
					//请求到的数据中的时间
					amount(dataTime);
					ajaxRequest(dataTime);
				}

				//本月数据
				function thisMonth(response) {
					//获取本月时间
					//获得本月的开始日期
					time1 = getMonthStartDate() + " " + "00:00:00";
					time2 = getYesterday() + " " + "23:59:59";
					amount(dataTime);
					ajaxRequest(dataTime);
				}

				//上月数据
				function lastMouth(response) {
					//获取上月时间
					time1 = getLastMonthStartDate() + " " + "00:00:00";
					time2 = getLastMonthEndDate() + " " + "23:59:59";
					amount(dataTime);
					ajaxRequest(dataTime);
				}

				//自定义数据
				function zidingyi(response) {
					amount(dataTime);
					ajaxRequest(dataTime);
				}

				//本周数据
				function lastweek(data) {
					time1 = getWeekStartDate() + " " + "00:00:00";
					time2 = getWeekEndDate() + " " + "23:59:59";
					amount(dataTime);
					ajaxRequest(dataTime);
				}

				//数据渲染
				function dataX(res) {
					if(res.data == "" && countA == 1) {
						statusSign = true;
						$(".noData").css("display", "block");
					} else {
						$(".noData").css("display", "none");
						var count = people = 0; //收款金额和新增会员的人数
						var resa = res.data;
						countA++;
						if(resa.length < pageNum) {
							statusSign = true;
						}
						for(var i=0;i<resa.length;i++){
							if(resa[i].created_at){
								var str = "";
								str = '<li class="mui-table-view-cell mui-media list_d" data-id="' + resa[i].out_trade_no + '" data-auth="'+resa[i].trade_no+'">';
								str+='<a class="list_detail">'
								str+='<img class="mui-media-object mui-pull-left" src="' + imageN(resa[i].pay_type) + '">';
								str+='<div class="mui-media-body">' + resa[i].created_at.date.substring(0, 19) + '<p class=mui-ellipsis>' + resa[i].pay_status_txt + '</p>'
								str+='<span>' + resa[i].total_amount + '</span></div></a></li>';
								$('.listResult').append(str); //数据渲染 
							}
						}
					}
				}

				function imageN(payType) { //图片函数
					var sta = "";
					if(payType == "支付宝") {
						sta = "../img/zhifubao.png";
					} else if(payType == "微信") {
						sta = "../img/weixin.png";
					} else if(payType == "银行卡"){
						sta = "../img/SfBank.png";
					}else {
						sta = "../img/dp.png";
					}
					return sta;
				}

				function payStatus(numb) {
					var sta = ""
					switch(numb) {
						case 1:
							sta = "支付成功";
							break;
						case 2:
							sta = "支付取消";
							break;
						case 3:
							sta = "等待支付";
							break;
						case 4:
							sta = "已退款";
							break;
						case 5:
							sta = "订单关闭";
							break;
					}
					return sta;
				}

				//点击对应的订单，跳转到订单详情页面
				mui('body').on('tap', '.list_d', function() {
					//获取该数据的订单号，作为跳转至新页面的参数
					mui.openWindow({url:"../view/detail.html", id:'detail.html',extras:{
						orderNum: $(this).attr("data-id"),
						authNo: $(this).attr("data-auth")
					}});
				});

				//点击打印列表
				mui("body").on("tap", ".print", function() {
					var str = '<form class="mui-input-group"><div class="mui-input-row mui-checkbox mui-left"><label>汇总</label>';
					str+='<input name="checkbox0" value="0" type="checkbox" checked></div><div class="mui-input-row mui-checkbox mui-left">';
					str+='<label>明细</label><input name="checkbox1" value="1" type="checkbox"></div></form>';
					mui.confirm(str, "是否打印？", ["打印", "取消"], function(e) {
						if(e.index == 0) {
							var check0=$("input[name='checkbox0']").eq(0);
							var check1=$("input[name='checkbox1']").eq(0);
							plus.nativeUI.showWaiting("正在打印中，请勿退出.....");
							var macType="V1";
							if(getSysInfo().search("P1")!= -1){
						        macType="P1";
						    }else if(getSysInfo().search("V1")!= -1){
						        macType="V1";
						    }else if(getSysInfo().search("JICAI")!= -1){
						    	macType="JICAI";
						    }
							require(weburl + model_print, "json", "post", {
								token: localStorage.getItem("token"),
								time_type: dataTime ? dataTime : "0",
								time_start: time1,
								time_end: time2,
								print_kind1:check0.is(":checked")?"1":"0",
								print_kind2:check1.is(":checked")?"1":"0",
								macType: macType
							}, function(reponse) {
								plus.nativeUI.closeWaiting();
								if(reponse.status == "success") {
									console.log(JSON.stringify(reponse))
									printAct(reponse.data[0].content);
//									var str = reponse.data[0].print_content;
//									var reg = /\\n/g;
//									str = str.replace(reg, '\n');
//									print(str, 5, 48);
								} else {
									mui.closePopups();
									mui.alert(reponse.msg, " ", "关闭", function() {}, "div");
								}
							}, function() {
								mui.alert("网络错误，请稍后再试", " ", "关闭", function() {}, "div");
							})

						}

					}, "div");

				})
				if(mui.os.plus) {
					mui.plusReady(function() {
						setTimeout(function() {
							mui('#pullrefresh').pullRefresh().pullupLoading();
							Bluetooth();
						}, 1000);
					});
				} else {
					mui.ready(function() {
						mui('#pullrefresh').pullRefresh().pullupLoading();
						Bluetooth();
					});
				}
			})
		</script>
	</body>

</html>